package com.github.netty;

import com.github.netty.config.DefaultAbstractNettyConfigurer;
import com.github.netty.config.IServerConfig;
import com.github.netty.context.NettyApplicationContext;
import com.github.netty.listener.NettyApplicationListener;
import com.github.netty.properties.NettyProperties;
import com.github.netty.server.NettyServer;
import com.github.netty.service.IBusinessMessageHandler;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

/**
 * @author ArchieSean
 * @description 自动装配类
 * @date 2024-08-06
 */

@AutoConfiguration(after = NettyApplicationContext.class)
@EnableConfigurationProperties(NettyProperties.class)
@ComponentScan(basePackages = {"com.github.netty"})
public class NettyAutoConfiguration {

    public NettyAutoConfiguration(){}

    /**
     * 核心业务处理bean
     * @return obj
     */
    @Bean
    @ConditionalOnMissingBean
    public IBusinessMessageHandler iBusinessMessageHandler(){
        return (channel, message) -> {
          //自定义实现这个bean。用于业务处理。
        };
    }
    /**
     * netty默认配置
     * @return nettyConfig
     */
    @Bean
    @ConditionalOnMissingBean
    public IServerConfig serverConfig(){
        return new DefaultAbstractNettyConfigurer();
    }

    /**
     * netty主启动类
     * @return server
     */
    @Bean
    @ConditionalOnMissingBean
    public NettyServer nettyServer(){
        return new NettyServer();
    }


    /**
     * 用于启动netty服务
     * @return 监听器
     */
    @Bean
    @ConditionalOnMissingBean
    public NettyApplicationListener nettyApplicationListener(){
        return new NettyApplicationListener();
    }


}
